package com.liucxu.qiushimeinv.View.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.liucxu.qiushimeinv.Model.Bean.GirlEntity;
import com.liucxu.qiushimeinv.R;
import com.liucxu.qiushimeinv.Utils.GlideUtils;
import com.liucxu.qiushimeinv.Utils.ViewHolderUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 美女列表的adapter
 * Created by liukanshan on 2017/1/1.
 */

public class GirlsAdapter extends BaseAdapter {

    private List<GirlEntity> datas = new ArrayList<>();
    private Context mContext;

    public GirlsAdapter(Context context, ArrayList<GirlEntity> entities) {
        if (entities != null) {
            datas.clear();
            datas.addAll(entities);
            mContext = context;
        }
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = View.inflate(mContext, R.layout.adapter_girls, null);
        }
        initView(i,view);
        return view;
    }

    public void setDatas(ArrayList<GirlEntity> entities) {
        if (entities != null) {
            datas.clear();
            datas.addAll(entities);
            notifyDataSetChanged();
        }
    }

    private void initView(int position, View view) {
        GirlEntity girl = datas.get(position);
        ImageView girl_imv = ViewHolderUtils.get(view, R.id.girl_imv);
        GlideUtils.getInstance().loadSimpleContextVitMap(mContext, girl.getImgUrl(), girl_imv);
        TextView title=ViewHolderUtils.get(view,R.id.title);
        title.setText(girl.getTitle());
    }
}
